package servlets;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import domainObjects.Dossier;
import beans.InfractionBean;

/**
 * Servlet implementation class VisualiserDossier
 */
public class VisualiserDossier extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public VisualiserDossier() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		InfractionBean infractionBean = new InfractionBean();		
		Dossier dossier = (Dossier)request.getSession().getAttribute("CurrentDossier");
		if(dossier == null)
		{
			response.sendRedirect("/equipe6-log720-A11-lab2/VisualiserDossier.jsp");
			return;
		}
		try {
			dossier.setListInfraction(infractionBean.getDossierInfractions(dossier.id()));
		} catch (SQLException e) {
			response.sendRedirect("/equipe6-log720-A11-lab2/VisualiserDossier.jsp");
			return;
		}
		request.getSession().setAttribute("CurrentDossier", dossier);
		response.sendRedirect("/equipe6-log720-A11-lab2/VisualiserDossier.jsp");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
